<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>ajaxXMLHttpRequest(ch2)</title>

<script type="text/javascript">
<!--
/*
 * date : 2011.02.17
 * author : ljw
 * title : XMLHttpRequest 객체를 생성하는 method
 */

var httpRequest = null; 		//XMLHttpRequest 객체 선언(전역번수_

function getXMLHttpRequest(){
	
	if(window.ActiveXObject){  	//IE를 위한 XMLHttpRequest 객체 구하기
		try{
			return new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				return new ActiveXOjbect("Microsoft.XMLHTTP");
			}catch(e){
				return null;
			}
		}
	}else if(window.XMLHttpRequest){		//IE를 제외한 나머지 브라우저 XMLHttpRequest 객체 구하기
		return new XMLHttpRequest();
	}else{
		return null;
	}
}


function click_test(url){
	
	httpRequest = getXMLHttpRequest();				//1.XMLHttpRequest 객체를 구한다
	httpRequest.onreadystatechange = jspMessage;	//2.callback function 설정
	httpRequest.open("POST",url, true);				//3.전송설정(방식-POST/GET, 요청URL, 동기(FALSE) 비동기(TRUE) )
	httpRequest.send();								//4.server에 요청
}

function jspMessage(){
	
	if(httpRequest.readyState == 4){				//응답이 완료가 끝난 상태 == 4
		if(httpRequest.status == 200){				//응답이 정상적으로 왔는지 체크
			alert(httpRequest.responseText);		//정상인경우 alert으로 메세지 확인
			document.getElementById("testDiv").innerHTML=httpRequest.responseText ;		//innerHTML변경
		}else{
			alert(httpRequest.status);
		}
	}	
}
</script>

</head>
<body>
<form>
	<input type="button" value="simple.jsp" onclick="click_test(this.value)"/>
	<div id="testDiv" style="display:;"></div>
</form>
</body>
</html>